package com.tenebrous.jestic;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ExitCodeGenerator;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.ContextStoppedEvent;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import tk.mybatis.spring.annotation.MapperScan;

/**
 * jestic-server
 */
@Slf4j
@EnableAsync
@EnableScheduling
@MapperScan(basePackages = "com.tenebrous.jestic.mapper.idao.**")
@SpringBootApplication(scanBasePackages = {"com.tenebrous.jestic"})
public class JesticServerApplication {

    public static void main(String[] args) {
        SpringApplication sa = new SpringApplication(JesticServerApplication.class);
        sa.addListeners(new StartListener());
        sa.addListeners(new CloseListener());
        sa.run(args);
    }

    @Bean
    public ExitCodeGenerator exitCodeGenerator() {
        return () -> 432;
    }

    private static class StartListener implements ApplicationListener<ContextRefreshedEvent> {
        @Override
        public void onApplicationEvent(ContextRefreshedEvent applicationEvent) {
            log.debug("JesticApplication服务启动......");
        }
    }

    private static class CloseListener implements ApplicationListener<ContextStoppedEvent> {
        @Override
        public void onApplicationEvent(ContextStoppedEvent applicationEvent) {
            log.debug("JesticApplication服务关闭......");
        }
    }
}
